package chan.project.smartlawcommon.config;// RabbitMQConfig.java

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String LEGAL_EXCHANGE = "legal.exchange";

    public static final String LEGAL_QUEUE = "legal.queue";
    public static final String INSTRUMENT_QUEUE = "instrument.queue";

    public static final String ROUTING_KEY_LEGAL = "type.legal";
    public static final String ROUTING_KEY_INSTRUMENT = "type.instrument";
    // 声明 Direct Exchange
    @Bean
    public DirectExchange legalExchange() {
        return new DirectExchange(LEGAL_EXCHANGE, true, false); // 持久化，非自动删除
    }

    // 声明队列：法律法规
    @Bean
    public Queue legalQueue() {
        return new Queue(LEGAL_QUEUE, true);
    }

    // 声明队列：法律文书
    @Bean
    public Queue instrumentQueue() {
        return new Queue(INSTRUMENT_QUEUE, true);
    }
    
    @Bean
    public Binding bindingLegal(@Qualifier("legalQueue") Queue legalQueue, DirectExchange legalExchange) {
        return BindingBuilder.bind(legalQueue).to(legalExchange).with(ROUTING_KEY_LEGAL);
    }
    
    @Bean
    public Binding bindingInstrument(@Qualifier("instrumentQueue") Queue instrumentQueue, DirectExchange legalExchange) {
        return BindingBuilder.bind(instrumentQueue).to(legalExchange).with(ROUTING_KEY_INSTRUMENT);
    }
}